package com.fbinggun.dt.task.conditions;

import com.fbinggun.dt.DailyTask;
import com.fbinggun.dt.player.PlayerData;
import com.fbinggun.dt.task.Task;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDeathEvent;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class KillEntity extends Conditions{

    List<String> list = new ArrayList<>();

    public KillEntity(String id, ConfigurationSection config, Task task) {
        super(id, config, task);
        list=config.getStringList("Type");
    }



    @EventHandler
    public void on(EntityDeathEvent event) throws SQLException, ClassNotFoundException {
        if(event.getEntity().getKiller()!=null){
            Player player = event.getEntity().getKiller();
            if(isRun(player)){
                String entityName = event.getEntity().getType().getName().toUpperCase();
                if (list == null || list.size() == 0) {
                    DailyTask.debug("玩家击杀生物 ：" + entityName);
                    addCount(player, 1);
                } else {
                    DailyTask.debug("玩家击杀生物 ：" + entityName);
                    if (list.contains(entityName)) {
                        DailyTask.debug("玩家增加任务进度 ：" + entityName);
                        addCount(player, 1);
                    }
                }
            }
        }

    }




}
